package com.doupi.partner.dal;

import com.doupi.partner.model.UserRelation;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

public interface UserRelationMapper {
	int deleteByPrimaryKey(Long id);

	int insert(UserRelation record);

	UserRelation selectByPrimaryKey(Long id);

	int updateByPrimaryKeySelective(UserRelation record);

	int countUserRelation(UserRelation userRelation);

	List<UserRelation> queryUserRelations(UserRelation userRelation, RowBounds rowBounds);

	List<UserRelation> selectUserRelationForUpdate(UserRelation userRelation);

	UserRelation selectUserRelationForUpdateByPrimaryKey(Long id);

	@Select("<script>select count(1) from t_user_relation  <where> " + "<trim prefix=\"and (\" suffix=\")\" prefixOverrides=\"OR\">"
			+ " <if test=\"partnerAdministratorId != null\">or partner_administrator_id = #{partnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"superiorPartnerAdministratorId != null\">or superior_partner_administrator_id = #{superiorPartnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"cityAdministratorId != null\">or city_administrator_id = #{cityAdministratorId, jdbcType=BIGINT}</if>"
			+ " <if test=\"substationAdministratorId != null\">or substation_administrator_id = #{substationAdministratorId,jdbcType=BIGINT}</if>" + " </trim>" + " </where></script>")
	int countUserRelationWithAnnotation(UserRelation userRelation);

	@Select("<script>select * from t_user_relation  <where> " + "<trim prefix=\"and (\" suffix=\")\" prefixOverrides=\"OR\">"
			+ " <if test=\"partnerAdministratorId != null\">or partner_administrator_id = #{partnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"superiorPartnerAdministratorId != null\">or superior_partner_administrator_id = #{superiorPartnerAdministratorId,jdbcType=BIGINT}</if> "
			+ " <if test=\"cityAdministratorId != null\">or city_administrator_id = #{cityAdministratorId, jdbcType=BIGINT}</if>"
			+ " <if test=\"substationAdministratorId != null\">or substation_administrator_id = #{substationAdministratorId,jdbcType=BIGINT}</if>" + " </trim>"
			+ " </where>  order by create_time desc </script>")
	@ResultMap("com.doupi.partner.dal.UserRelationMapper.BaseResultMap")
	List<UserRelation> queryUserRelationWithAnnotation(UserRelation userRelation, RowBounds rowBounds);
}
